﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Intersection
{
    public partial class Form1 : Form
    {
        private ObsData data;

        public Form1()
        {
            InitializeComponent();
            dataGridInit();
        }

        private void dataGridInit()
        {
            dataGridView1.Columns.Add("blank", "");
            dataGridView1.Columns.Add("left","左片");
            dataGridView1.Columns.Add("right", "右片");
            dataGridView1.Rows.Add(8);
            dataGridView1.Rows[0].Cells[0].Value = "Xs";
            dataGridView1.Rows[1].Cells[0].Value = "Ys";
            dataGridView1.Rows[2].Cells[0].Value = "Zs";
            dataGridView1.Rows[3].Cells[0].Value = "phi";
            dataGridView1.Rows[4].Cells[0].Value = "omega";
            dataGridView1.Rows[5].Cells[0].Value = "kappa";
            dataGridView1.Rows[6].Cells[0].Value = "x";
            dataGridView1.Rows[7].Cells[0].Value = "y";
            dataGridView1.Rows[8].Cells[0].Value = "f";
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFile();
        }

        private void 打开OToolStripButton_Click(object sender, EventArgs e)
        {
            openFile();
        }

        private void openFile()
        {
            //openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt";
            //openFileDialog1.FilterIndex = 2;
            //openFileDialog1.RestoreDirectory = true;

            openFileDialog1.Title = "打开内外方位元素文件";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                data = FileManager.ReadImageParam(openFileDialog1.FileName);
                updateGridView();
            }

            openFileDialog1.Title = "打开同名点坐标文件";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileManager.ReadCorrPoints(ref data, openFileDialog1.FileName);
            }
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void updateGridView()
        {
            dataGridView1.Rows[0].Cells[1].Value = data.Img_left.Xs;
            dataGridView1.Rows[1].Cells[1].Value = data.Img_left.Ys;
            dataGridView1.Rows[2].Cells[1].Value = data.Img_left.Zs;
            dataGridView1.Rows[3].Cells[1].Value = data.Img_left.phi;
            dataGridView1.Rows[4].Cells[1].Value = data.Img_left.omega;
            dataGridView1.Rows[5].Cells[1].Value = data.Img_left.kappa;
            dataGridView1.Rows[6].Cells[1].Value = data.Img_left.x;
            dataGridView1.Rows[7].Cells[1].Value = data.Img_left.y;
            dataGridView1.Rows[8].Cells[1].Value = data.Img_left.f;

            dataGridView1.Rows[0].Cells[2].Value = data.Img_right.Xs;
            dataGridView1.Rows[1].Cells[2].Value = data.Img_right.Ys;
            dataGridView1.Rows[2].Cells[2].Value = data.Img_right.Zs;
            dataGridView1.Rows[3].Cells[2].Value = data.Img_right.phi;
            dataGridView1.Rows[4].Cells[2].Value = data.Img_right.omega;
            dataGridView1.Rows[5].Cells[2].Value = data.Img_right.kappa;
            dataGridView1.Rows[6].Cells[2].Value = data.Img_right.x;
            dataGridView1.Rows[7].Cells[2].Value = data.Img_right.y;
            dataGridView1.Rows[8].Cells[2].Value = data.Img_right.f;

        }

        private void toolStripButton1_Click_1(object sender, EventArgs e)
        {
            Intersection intersection = new Intersection(data);
            intersection.Compute();
        }
    }
}
